package com.sks.bean.pojo;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;

/**
 * Area entity. @author MyEclipse Persistence Tools
 */
@Entity
@JsonIgnoreProperties(value={"hibernateLazyInitializer"})  
@Table(name = "area", uniqueConstraints = @UniqueConstraint(columnNames = "name"))
public class Area implements java.io.Serializable {

	// Fields

	private Integer areaId;
	private Area parentArea;
	private String name;
	private Boolean visible;
	private String remark;
	private List<Area> areas;
	//private List<House> houses = new HashSet<House>(0);
	//private List<Building> buildings = new HashSet<Building>(0);

	// Constructors

	/** default constructor */
	public Area() {
	}

	/** minimal constructor */
	public Area(String name) {
		this.name = name;
	}

	/** full constructor */
	public Area(Area parentArea, String name, Boolean visible, String remark,
			List<Area> areas, List<House> houses, List<Building> buildings) {
		this.parentArea = parentArea;
		this.name = name;
		this.visible = visible;
		this.remark = remark;
		this.areas = areas;
		//this.houses = houses;
		//this.buildings = buildings;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "areaId", unique = true, nullable = false)
	public Integer getAreaId() {
		return this.areaId;
	}

	public void setAreaId(Integer areaId) {
		this.areaId = areaId;
	}

	@ManyToOne(fetch = FetchType.LAZY, cascade = {})
	@JsonBackReference
	@JoinColumn(name = "parentId", unique = false, nullable = true, insertable = true, updatable = true)
	public Area getParentArea() {
		return this.parentArea;
	}

	public void setParentArea(Area parentArea) {
		this.parentArea = parentArea;
	}

	@Column(name = "name", unique = true, nullable = false, length = 32)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "visible")
	public Boolean getVisible() {
		return this.visible;
	}

	public void setVisible(Boolean visible) {
		this.visible = visible;
	}

	@Column(name = "remark", length = 100)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "parentArea")
	@OrderBy("areaId ASC")
	public List<Area> getAreas() {
		return this.areas;
	}

	public void setAreas(List<Area> areas) {
		this.areas = areas;
	}

	/*@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "area")
	public List<House> getHouses() {
		return this.houses;
	}

	public void setHouses(List<House> houses) {
		this.houses = houses;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "area")
	public List<Building> getBuildings() {
		return this.buildings;
	}

	public void setBuildings(List<Building> buildings) {
		this.buildings = buildings;
	}*/

}